package com.bw.paper.mvp.view.Activity;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.blankj.utilcode.util.LogUtils;
import com.bumptech.glide.Glide;
import com.bw.paper.App;
import com.bw.paper.R;
import com.bw.paper.db.UserEntityDao;
import com.bw.paper.entity.UserEntity;
import com.bw.paper.utils.StatusBarColorUtils;

import constant.DownLoadBy;
import model.UpdateConfig;
import update.UpdateAppUtils;

public class MoreActivity extends StatusBarColorUtils implements View.OnClickListener {


    private boolean flag = true;
    private boolean flag1 = false;
    private boolean flag2 = false;
    private RelativeLayout settingRelative;
    private RelativeLayout settingRelative1;
    private ImageView headBackImg;
    private LinearLayout settingRelative2;
    private ImageView settingHeadimg;
    private ImageView settingImg;
    private RelativeLayout settingRelative3;
    private ImageView settingImg2;
    private RelativeLayout settingRelative4;
    private RelativeLayout settingRelative5;
    private ImageView settingImg3;
    private RelativeLayout settingRelative6;
    private LinearLayout settingRelative7;
    private ImageView settingImg4;
    private LinearLayout settingRelative8;
    private ImageView settingImg5;
    private LinearLayout settingRelative9;
    private ImageView settingImg6;
    private RelativeLayout settingRelative10;
    private RelativeLayout settingRelative11;
    private RelativeLayout settingRelative12;
    private RelativeLayout settingRelative13;
    private RelativeLayout settingRelative14;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_more);
        initView();
        headBackImg.setOnClickListener(this::onClick);
        try {
            LogUtils.json(App.getInstance().getDaoSession().loadAll(UserEntity.class));
        } catch (Exception e) {
            e.printStackTrace();
        }
        setStatusBarColor(Color.WHITE);
        UserEntity unique = null;
        try {
            unique = App.getInstance().getDaoSession().queryBuilder(UserEntity.class).where(UserEntityDao.Properties.Id.eq(0)).unique();
        } catch (Exception e) {
            e.printStackTrace();
        }
//        String user_img = unique.getUser_img();
//        Glide.with(this).load(user_img).circleCrop().into(settingHeadimg);
        headBackImg.setOnClickListener(this::onClick);
        settingImg4.setOnClickListener(this::onClick);
        settingImg5.setOnClickListener(this::onClick);
        settingImg6.setOnClickListener(this::onClick);
        settingRelative2.setOnClickListener(this::onClick);
        settingRelative3.setOnClickListener(this::onClick);
        settingRelative14.setOnClickListener(this::onClick);
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.head_back_img) {
            finish();
        }
        if (id == R.id.setting_relative2) {
            startPage(UpUserActivity.class);
            finish();
        }
        if (id == R.id.setting_relative3) {
            startPage(ExitActivity.class);
        }
        if (id == R.id.setting_relative14) {
            UpdateConfig config=new UpdateConfig(true,true,false,false,false
                    , "","apk.1.1"
                    , DownLoadBy.APP
                    ,false,true
                    ,0
                    ,false,true,
                    "",2);
            UpdateAppUtils.getInstance().apkUrl("")
                    .updateTitle("更新版本")
                    .updateContent("")
                    .updateConfig(config)
                    .update();
        }
        if (id == R.id.setting_img4) {
            if (flag) {
                flag = false;
                settingImg4.setImageResource(R.drawable.new_off);
            } else {
                flag = true;
                settingImg4.setImageResource(R.drawable.new_on);
            }
        }
        if (id == R.id.setting_img5) {
            if (flag1) {
                flag1 = false;
                settingImg5.setImageResource(R.drawable.new_off);
            } else {
                flag1 = true;
                settingImg5.setImageResource(R.drawable.new_on);
            }
        }
        if (id == R.id.setting_img6) {
            if (flag2) {
                flag2 = false;
                settingImg6.setImageResource(R.drawable.new_off);
            } else {
                flag2 = true;
                settingImg6.setImageResource(R.drawable.new_on);
            }
        }
    }

    private void initView() {
        settingRelative = (RelativeLayout) findViewById(R.id.setting_relative);
        settingRelative1 = (RelativeLayout) findViewById(R.id.setting_relative1);
        headBackImg = (ImageView) findViewById(R.id.head_back_img);
        settingRelative2 = (LinearLayout) findViewById(R.id.setting_relative2);
        settingHeadimg = (ImageView) findViewById(R.id.setting_headimg);
        settingImg = (ImageView) findViewById(R.id.setting_img);
        settingRelative3 = (RelativeLayout) findViewById(R.id.setting_relative3);
        settingImg2 = (ImageView) findViewById(R.id.setting_img2);
        settingRelative4 = (RelativeLayout) findViewById(R.id.setting_relative4);
        settingRelative5 = (RelativeLayout) findViewById(R.id.setting_relative5);
        settingImg3 = (ImageView) findViewById(R.id.setting_img3);
        settingRelative6 = (RelativeLayout) findViewById(R.id.setting_relative6);
        settingRelative7 = (LinearLayout) findViewById(R.id.setting_relative7);
        settingImg4 = (ImageView) findViewById(R.id.setting_img4);
        settingRelative8 = (LinearLayout) findViewById(R.id.setting_relative8);
        settingImg5 = (ImageView) findViewById(R.id.setting_img5);
        settingRelative9 = (LinearLayout) findViewById(R.id.setting_relative9);
        settingImg6 = (ImageView) findViewById(R.id.setting_img6);
        settingRelative10 = (RelativeLayout) findViewById(R.id.setting_relative10);
        settingRelative11 = (RelativeLayout) findViewById(R.id.setting_relative11);
        settingRelative12 = (RelativeLayout) findViewById(R.id.setting_relative12);
        settingRelative13 = (RelativeLayout) findViewById(R.id.setting_relative13);
        settingRelative14 = (RelativeLayout) findViewById(R.id.setting_relative14);


    }

    @Override
    public View addStatusView() {
        return f(R.id.setting_relative);
    }
}